/*==============================================================================================================================================================							ADOPTING A NEW RELIGION:			  THE CASE OF PROTESTANTISM IN 16TH CENTURY GERMANY			   			                    DAVIDE CANTONI			   							  REPLICATION PACKAGE								                                ================================================================================- LAST UPDATE: 2019/01/07- STRUCTURE: This program replicates the figures and tables of the paper grouped		by datasets used:			PART 1: Figures using adopting_replication.dta 			=> Figures 1, 2			=> Tables 1, 2, 3				PART 2: Figures using adopting_replication_cities.dta			=> Figures  			=> Table 4 				PART 3: Figures using adopting_replication_panel.dta 			=> Tables 5, 6 - PREPARATION: This do file relies on the following user-written commands:=> outreg2  => sphdistIf you have not done so already, please install them before running this file.==============================================================================================================================================================*/clear allversion 9.2set more offglobal path ""	/* PLEASE UPDATE PATH */ cd "$path/Outreg files"/*==============================================================================                  PART 1: Figures & tables using main dataset==============================================================================*/	*** TERRITORY-LEVEL REGRESSIONS*** prepare territory-level dataset	use "$path/adopting_replication.dta"				* prepare covariates		replace reichsmatrikel=reichsmatrikel/1000			gen princeage_1517=1517-gebjahr_fuerst1517		gen princeage_1526=1526-gebjahr_fuerst1526		gen princeage_1555=1555-gebjahr_fuerst1555				xtile princeage_1517_terc = princeage_1517, n(3)		qui tab princeage_1517_terc, gen(princeage_1517_terc)		xtile princeage_1526_terc = princeage_1526, n(3)		qui tab princeage_1526_terc, gen(princeage_1526_terc)		xtile princeage_1555_terc = princeage_1555, n(3)		qui tab princeage_1555_terc, gen(princeage_1555_terc)			* geographic distances (Wittenberg, Zurich, Geneva)			#delimit ;					gen latdegwitt=51; gen latminwitt=52; gen longdegwitt=12; gen longminwitt=39;		sphdist, gen(distwitt) lat1(latitude) lon1(longitude) lat2(latdegwitt latminwitt) lon2(longdegwitt longminwitt);		drop latdegwitt latminwitt longdegwitt longminwitt;					gen latdegzu=47; gen latminzu=23; gen longdegzu=8; gen longminzu=32;		sphdist, gen(distzu) lat1(latitude) lon1(longitude) lat2(latdegzu latminzu) lon2(longdegzu longminzu);		drop latdegzu latminzu longdegzu longminzu;					gen latdegge=46; gen latminge=12; gen longdegge=6; gen longminge=9;		sphdist, gen(distge) lat1(latitude) lon1(longitude) lat2(latdegge latminge) lon2(longdegge longminge);		drop latdegge latminge longdegge longminge;				#delimit cr				replace distwitt=distwitt/100		replace distzu=distzu/100		replace distge=distge/100			* summary statistics			local counter=0		gen variable=""		gen mean=.		gen sd=.		gen min=.		gen max=.		gen meancat=.		gen meanpro=.		gen t=.		foreach V of varlist t_protestant_at_t latitude longitude n_cities logu_1500 reichsmatrikel university elector ecclesiastical_at_t_1500 reichsstadt distwitt princeage_15* {			local counter=`=`counter'+1'			replace variable="`V'" in `counter'			qui sum `V' if reichsmatrikel<.			replace mean=r(mean) in `counter'			replace sd=r(sd) in `counter'			replace min=r(min) in `counter'			replace max=r(max) in `counter'			qui ttest `V' if reichsmatrikel<., by(t_protestant_at_t) unequal			replace meancat=r(mu_1) in `counter'			replace meanpro=r(mu_2) in `counter'			replace t=r(t) in `counter'		}				list variable mean sd min max meancat meanpro t in 1/`counter', clean		* regressions	* table 2			keep if reichsmatrikel<.				reg t_protestant_at_t latitude longitude, cluster(uppertcode)		outreg2 using adopting_replication.xls, br bdec(3) ctitle("T2 C1, Geography") addstat(N of clusters, e(N_clust)) replace		reg t_protestant_at_t n_cities logu_1500 reichsmatrikel university, cluster(uppertcode)		outreg2 using adopting_replication.xls, br bdec(3) ctitle("T2 C2, Economy") addstat(N of clusters, e(N_clust)) 				reg t_protestant_at_t elector ecclesiastical_at_t_1500 reichsstadt, cluster(uppertcode)		outreg2 using adopting_replication.xls, br bdec(3) ctitle("T2 C3, Institutions") addstat(N of clusters, e(N_clust))				reg t_protestant_at_t distwitt, cluster(uppertcode)		outreg2 using adopting_replication.xls, br bdec(3) ctitle("T2 C4, Information") addstat(N of clusters, e(N_clust))		reg t_protestant_at_t latitude longitude n_cities logu_1500 reichsmatrikel university elector ecclesiastical_at_t_1500 reichsstadt distwitt, cluster(uppertcode)		outreg2 using adopting_replication.xls, br bdec(3) ctitle("T2 C5, All") addstat(N of clusters, e(N_clust))	* table 3		reg t_protestant_at_t latitude longitude n_cities logu_1500 reichsmatrikel university ecclesiastical_at_t_1500 reichsstadt distwitt if reichsstadt==0, cluster(uppertcode)		outreg2 using adopting_replication.xls, br bdec(3) ctitle("T3 C1, Excl. FIC") addstat(N of clusters, e(N_clust))		reg t_protestant_at_t latitude longitude n_cities logu_1500 reichsmatrikel university ecclesiastical_at_t_1500 reichsstadt distwitt if reichsstadt==0 & ecclesiastical_at_t_1500==0, cluster(uppertcode)		outreg2 using adopting_replication.xls, br bdec(3) ctitle("T3 C2, Excl. FIC and Eccl") addstat(N of clusters, e(N_clust))		reg t_protestant_at_t latitude longitude n_cities logu_1500 reichsmatrikel university ecclesiastical_at_t_1500 distwitt princeage_1517_terc1 princeage_1517_terc3, cluster(uppertcode)		outreg2 using adopting_replication.xls, br bdec(3) ctitle("T3 C3, Prince Age") addstat(N of clusters, e(N_clust))		reg t_protestant_at_t latitude longitude n_cities logu_1500 reichsmatrikel university ecclesiastical_at_t_1500 distwitt princeage_1526_terc1 princeage_1526_terc3, cluster(uppertcode)		outreg2 using adopting_replication.xls, br bdec(3) ctitle("T3 C4, Prince Age") addstat(N of clusters, e(N_clust))		reg t_protestant_at_t latitude longitude n_cities logu_1500 reichsmatrikel university ecclesiastical_at_t_1500 distwitt princeage_1555_terc1 princeage_1555_terc3, cluster(uppertcode)		outreg2 using adopting_replication.xls, br bdec(3) ctitle("T3 C5, Prince Age") addstat(N of clusters, e(N_clust))/*==============================================================================                  PART 2: Figures & tables using city-level dataset==============================================================================*/	*** CITY-LEVEL REGRESSIONS*** prepare city-level dataset	use "$path/adopting_replication_cities.dta", replace	gen growth_1300_1500=100*((u_1500/u_1300)-1)	gen growth_1400_1500=100*((u_1500/u_1400)-1)		qui sum growth_1300_1500, meanonly	replace growth_1300_1500=r(mean) if growth_1300_1500==.	qui sum growth_1400_1500, meanonly	replace growth_1400_1500=r(mean) if growth_1400_1500==.		replace u_1500=1 if u_1500==.	gen logu_1500=log(u_1500)		gen mon_pc=monasteries_nonmend_10km/u_1500	gen cityage=(1517-foundation)/100	drop if cityage<0		* geographic distances (Wittenberg, Zurich, Geneva)		#delimit ;						gen latdegwitt=51; gen latminwitt=52; gen longdegwitt=12; gen longminwitt=39;		sphdist, gen(distwitt) lat1(latitude) lon1(longitude) lat2(latdegwitt latminwitt) lon2(longdegwitt longminwitt);		drop latdegwitt latminwitt longdegwitt longminwitt;						gen latdegzu=47; gen latminzu=23; gen longdegzu=8; gen longminzu=32;		sphdist, gen(distzu) lat1(latitude) lon1(longitude) lat2(latdegzu latminzu) lon2(longdegzu longminzu);		drop latdegzu latminzu longdegzu longminzu;						gen latdegge=46; gen latminge=12; gen longdegge=6; gen longminge=9;		sphdist, gen(distge) lat1(latitude) lon1(longitude) lat2(latdegge latminge) lon2(longdegge longminge);		drop latdegge latminge longdegge longminge;				#delimit cr				replace distwitt=distwitt/100		replace distzu=distzu/100		replace distge=distge/100			* summary statistics				local counter=0		gen variable=""		gen mean=.		gen sd=.		gen min=.		gen max=.		gen meancat=.		gen meanpro=.		gen t=.		foreach V of varlist protestant_at_t latitude longitude river logu_1500 growth_1300_1500 cityage ecclesiastical_at_t_1500 mon_pc university reichsstadt hansa distwitt monasteries_aug_10km pressby1517 {			local counter=`=`counter'+1'			replace variable="`V'" in `counter'			qui sum `V' if cityid<4000			replace mean=r(mean) in `counter'			replace sd=r(sd) in `counter'			replace min=r(min) in `counter'			replace max=r(max) in `counter'			qui ttest `V', by(protestant_at_t) unequal			replace meancat=r(mu_1) in `counter'			replace meanpro=r(mu_2) in `counter'			replace t=r(t) in `counter'		}				list variable mean sd min max meancat meanpro t in 1/`counter', clean	* regressions	* table 4				reg protestant_at_t latitude longitude river, cluster(uppertcode)		outreg2 using adopting_replication_cities.xls, br bdec(3) ctitle("T4 C1, Geography") addstat(N of clusters, e(N_clust)) replace				reg protestant_at_t logu_1500 growth_1300_1500 cityage, cluster(uppertcode)		outreg2 using adopting_replication_cities.xls, br bdec(3) ctitle("T4 C2, Economy") addstat(N of clusters, e(N_clust)) 				reg protestant_at_t ecclesiastical_at_t_1500 mon_pc university reichsstadt hansa, cluster(uppertcode)		outreg2 using adopting_replication_cities.xls, br bdec(3) ctitle("T4 C3, Institutions") addstat(N of clusters, e(N_clust)) 				reg protestant_at_t distwitt monasteries_aug_10km pressby1517, cluster(uppertcode)		outreg2 using adopting_replication_cities.xls, br bdec(3) ctitle("T4 C4, Information") addstat(N of clusters, e(N_clust)) 				reg protestant_at_t latitude longitude river logu_1500 growth_1300_1500 cityage ecclesiastical_at_t_1500 mon_pc university reichsstadt hansa distwitt monasteries_aug_10km pressby1517, cluster(uppertcode)		outreg2 using adopting_replication_cities.xls, br bdec(3) ctitle("T4 C5, All") addstat(N of clusters, e(N_clust)) *** Graphsclearuse "$path/adopting_replication_cities.dta", replacecd "$path/Graphs"* Figures 2-3* geographic distances (Wittenberg, Zurich, Geneva)	#delimit ;			gen latdegwitt=51; gen latminwitt=52; gen longdegwitt=12; gen longminwitt=39;	sphdist, gen(distwitt) lat1(latitude) lon1(longitude) lat2(latdegwitt latminwitt) lon2(longdegwitt longminwitt);	drop latdegwitt latminwitt longdegwitt longminwitt;				#delimit crreplace u_1500=1 if u_1500==.gen firstrefpro=t_protestant_at_t*firstrefgen firstrefcat=(1-t_protestant_at_t)*firstrefreplace firstrefpro=. if firstrefpro==0replace firstrefcat=. if firstrefcat==0twoway (scatter firstrefpro distwitt [weight=u_1500] if firstref<1555, msymbol(Oh)) ///	(scatter firstrefcat distwitt [weight=u_1500] if firstref<1555, msymbol(Sh)), ///	scheme(s1mono) ytitle(First Protestant preacher documented) xtitle(Distance to Wittenberg) ///	legend(off)graph save firstref_vs_distwitt.gph, replacegraph export firstref_vs_distwitt.eps, as(eps) replacescatter protestant_at_t distwitt [weight=u_1500], msymbol(Oh) scheme(s1mono) yscale(range(-0.5 1.5)) ylabel(0 1) ytitle(Protestant in 1600) xtitle(Distance to Wittenberg)graph save pro_vs_distwitt.gph, replacegraph export pro_vs_distwitt.eps, as(eps) replaceclearinsheet using "$path/lutherseditions.txt"cd "$path/Graphs"* Figure 4* geographic distances (Wittenberg, Zurich, Geneva)	#delimit ;			gen latdegwitt=51; gen latminwitt=52; gen longdegwitt=12; gen longminwitt=39;	sphdist, gen(distwitt) lat1(latitude) lon1(longitude) lat2(latdegwitt latminwitt) lon2(longdegwitt longminwitt);	drop latdegwitt latminwitt longdegwitt longminwitt;				#delimit crdrop if editions1525==0 & editions1555==0label define citynames 0 "Wittenberg" 65 "Leipzig" 126 "Zwickau" 151 "Erfurt" 253 "Bamberg" 291 "Nuremberg" 410 "Augsburg" 483 "Hagenau" 504 "Strasbourg" 579 "Zurich" 602 "Basel"label values distwitt citynamestwoway bar editions1525 distwitt if editions1525>0, scheme(s1mono) barwidth(8) lcolor(black) ytitle("Number of editions of Luther's works") xtitle("Distance to Wittenberg") xlabel(0 65 126 151 253 291 410 483 504 579 602, valuelabel angle(vertical))graph save editions_vs_distwitt.gph, replacegraph export editions_vs_distwitt.eps, as(eps) replace/*==============================================================================                  PART 3: Figures & tables using panel dataset==============================================================================*/*** SPATIAL REGRESSIONS*** prepare spatial dataset	clear		use "$path/adopting_replication_panel.dta"	cd "$path/Outreg files"	* table 5: summary stats, date of introduction			egen refdate=rowtotal(refuntil1532 refuntil1540 refuntil1548 refuntil1555 refuntil1600 )		replace refdate=5-refdate				bysort refdate: summ distwitt			* prepare panel dataset for regressions				reshape long refneighbors refuntil, i(tcode) j(year)				gen time=.		bysort tcode (year): replace time=_n				tsset tcode time		gen kreisXtime=100*kreis+time							gen lagrefneighbors=.			bysort tcode (year): replace lagrefneighbors=refneighbors[_n-1]		replace lagrefneighbors=0 if time==1			gen leadrefneighbors=.		bysort tcode (year): replace leadrefneighbors=refneighbors[_n+1]					gen lagrefnXmat=lagrefneighbors*reichsmatrikel		drop if year==1621		* summary statistics		xi i.time*lagrefneighbors, noomit		replace _ItimXlagre_1=. if time~=1		replace _ItimXlagre_2=. if time~=2		replace _ItimXlagre_3=. if time~=3		replace _ItimXlagre_4=. if time~=4		replace _ItimXlagre_5=. if time~=5				gen protestant=1-(refdate==5)				local counter=0		gen variable=""		gen mean=.		gen sd=.		gen min=.		gen max=.		gen meancat=.		gen meanpro=.		gen t=.		foreach V of varlist refuntil lagrefneighbors _ItimXlagre_1 _ItimXlagre_2 _ItimXlagre_3 _ItimXlagre_4 _ItimXlagre_5 {			local counter=`=`counter'+1'			replace variable="`V'" in `counter'			qui sum `V'			replace mean=r(mean) in `counter'			replace sd=r(sd) in `counter'			replace min=r(min) in `counter'			replace max=r(max) in `counter'			qui ttest `V', by(protestant) unequal			replace meancat=r(mu_1) in `counter'			replace meanpro=r(mu_2) in `counter'			replace t=r(t) in `counter'		}				list variable mean sd min max meancat meanpro t in 1/`counter', clean		* regressions	* table 6		reg refuntil lagrefneighbors, cluster(kreisXtime) 		outreg2 using adopting_replication_panel.xls, br bdec(3) ctitle("T6 C1") addstat(N of clusters, e(N_clust)) replace		reg refuntil lagrefneighbors distwitt, cluster(kreisXtime) 		outreg2 using adopting_replication_panel.xls, br bdec(3) ctitle("T6 C2") addstat(N of clusters, e(N_clust)) 								xtreg refuntil lagrefneighbors, cluster(kreisXtime) nonest fe 		outreg2 using adopting_replication_panel.xls, br bdec(3) ctitle("T6 C3") addstat(N of clusters, e(N_clust)) 		xi: xtreg refuntil lagrefneighbors i.time, cluster(kreisXtime) nonest fe		outreg2 using adopting_replication_panel.xls, br bdec(3) ctitle("T6 C4") addstat(N of clusters, e(N_clust)) 		xi: xtreg refuntil leadrefneighbors i.time, cluster(kreisXtime) nonest fe		outreg2 using adopting_replication_panel.xls, br bdec(3) ctitle("T6 C5") addstat(N of clusters, e(N_clust)) 		xi: xtreg refuntil lagrefneighbors lagrefnXmat i.time, cluster(kreisXtime) nonest fe 		outreg2 using adopting_replication_panel.xls, br bdec(3) ctitle("T6 C6") addstat(N of clusters, e(N_clust)) 		xi i.time*lagrefneighbors i.time*distwitt, noomit		drop _Itime_1 _ItimXdistw_1		xtreg refuntil _Itime* _ItimXlagre_1 _ItimXlagre_2 _ItimXlagre_3 _ItimXlagre_4 _ItimXlagre_5 , cluster(kreisXtime) nonest fe		outreg2 using adopting_replication_panel.xls, br bdec(3) ctitle("T6 C7") addstat(N of clusters, e(N_clust)) 		xtreg refuntil _Itime* _ItimXlagre_1 _ItimXlagre_2 _ItimXlagre_3 _ItimXlagre_4 _ItimXlagre_5 _ItimXdistw*, cluster(kreisXtime) nonest fe		outreg2 using adopting_replication_panel.xls, br bdec(3) ctitle("T6 C8") addstat(N of clusters, e(N_clust)) 		